package heven.holt.wan.android.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.cachedIn
import dagger.hilt.android.lifecycle.HiltViewModel
import heven.holt.wan.android.extensions.requestCoroutine
import heven.holt.wan.android.model.BannerModel
import heven.holt.wan.android.repository.WanArticleRepository
import heven.holt.wan.android.repository.WanConfigRepository
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class HomeViewModel @Inject constructor(
    private val wanConfigRepository: WanConfigRepository,
    wanArticleRepository: WanArticleRepository
) : ViewModel() {
    val bannerLiveData: MutableLiveData<List<BannerModel>> = MutableLiveData()

    val flow = wanArticleRepository.getArticleListFlow().cachedIn(viewModelScope)

    fun requestBanner() {
        viewModelScope.launch {
            val result = requestCoroutine { wanConfigRepository.getBanner() }
            bannerLiveData.postValue(result)
        }
    }
}